<template>
  <section v-loading="loading" class="cms-body">
    <div class="cms-list-header flex-between">
      <!-- 右操作 -->
		    <div>
			    <el-select v-model="params.resourceTypeId" @change="queryByJson">
				    <el-option label="所有资源类型" value="0"></el-option>
				    <el-option v-for="(item,index) in resourceTypeGroup" :key="index" :label="item.typeName"
				               :value="item.id"></el-option>
			    </el-select>
			    <el-select v-model="params.resourceSubjectId" @change="queryByJson">
				    <el-option label="所有资源学科" value="0"></el-option>
				    <el-option v-for="(item,index) in resourceSubjectGroup" :key="index" :label="item.subjectName"
				               :value="item.id"></el-option>
			    </el-select>
			    <el-select v-model="params.resourceMajorId" @change="queryByJson">
				    <el-option label="所有资源专业" value="0"></el-option>
				    <el-option v-for="(item,index) in resourceMajorGroup" :key="index" :label="item.majorName"
				               :value="item.id"></el-option>
			    </el-select>
			    <el-select v-model="params.resourceCourseId" @change="queryByJson">
				    <el-option label="所有资源课程" value="0"></el-option>
				    <el-option v-for="(item,index) in resourceCourseGroup" :key="index" :label="item.courseName"
				               :value="item.id"></el-option>
			    </el-select>
			    <el-select v-model="params.resourceFormatId" @change="queryByJson">
				    <el-option label="所有资源格式" value="0"></el-option>
				    <el-option v-for="(item,index) in resourceFormatGroup" :key="index" :label="item.formatName"
				               :value="item.id"></el-option>
			    </el-select>
			    <cms-input label="资源名称" v-model="params.resourceName"></cms-input>
			    <el-button @click="queryByJson">查询</el-button>
		    </div>
    </div>
    <!-- 表格 -->
    <el-table :data="tableData" stripe style="width: 100%" @selection-change="checkIds">
      <el-table-column type="selection" width="65" align="center"></el-table-column>
      <el-table-column prop="resourceName" label="资源名称" width="180" align="center"></el-table-column>
	    <el-table-column prop="resourceInfo.resourceType.typeName" label="资源类型" align="center"></el-table-column>
	    <el-table-column prop="resourceInfo.resourceSubject.subjectName" label="资源学科" align="center"></el-table-column>
	    <el-table-column prop="resourceInfo.resourceMajor.majorName" label="资源专业" align="center"></el-table-column>
	    <el-table-column prop="resourceInfo.resourceCourse.courseName" label="资源课程" align="center"></el-table-column>
	    <el-table-column prop="resourceInfo.resourceFormat.formatName" label="资源格式" align="center"></el-table-column>
      <el-table-column prop="fileName" label="附件名称" align="center"></el-table-column>
      <el-table-column prop="uploadUser" label="上传人" align="center"></el-table-column>
      <el-table-column prop="status" label="是否公开" align="center">
        <div slot-scope="scope">
          <span style="color: #ff4949" v-if='scope.row.resourceStatus==="0"'>不公开</span>
          <span style="color: #13ce66" v-if='scope.row.resourceStatus==="1"'>公开</span>
        </div>
      </el-table-column>
      <el-table-column prop="resourceStatus" label="状态" align="center">
        <div slot-scope="scope">
          <span style="color: #ff4949" v-if='scope.row.status==="0"'>停用</span>
          <span style="color: #13ce66" v-if='scope.row.status==="1"'>启动</span>
        </div>
      </el-table-column>

    </el-table>
    <!-- 表格底部 -->
    <div class="cms-list-footer">
      <div class="cms-left">
        <el-button :disabled="disabled" @click="deleteBatch($api.publicResourceManageDelete,ids)"
                   v-perms="'/publicResourceManage/delete'"
        >批量删除
        </el-button>
      </div>
      <!-- cms分页组件 -->
      <cms-pagination :total="total" @change="getPages"></cms-pagination>
    </div>
  </section>
</template>

<script>
  import listMixins from '@/mixins/list'
  import {signParams} from '@/untils/sign';
  import axios from "axios";
  import qs from 'qs'

  export default {
    mixins: [listMixins],
    data() {
      return {
        params: {//只需要业务参数
          resourceName: "",
          resourceType: "0",
          pageNo: "",
          pageSize: ""
        }
        , downParam: {
          appId: '',
          sessionKey: '',
          names: '',
        },
        resourceTypeGroup: [],
      };
    },
    created() {
        this.getResourceTypeGroup();
        this.getResourceSubjectGroup();
        this.getResourceMajorGroup();
        this.getResourceCourseGroup();
        this.getResourceFormatGroup();
      this.initTableData(this.$api.publicResourceManageList, this.params);
    },
    methods: {
      down(val) {
        //下载
        let link = this.$store.state.sys.baseUrl + val;
        var a = document.createElement("a");
        a.href = link;
        a.click();
      },
        getResourceTypeGroup() {
            this.loading = true;
            axios.post(this.$api.resourceTypeGroup).then(res => {
                this.loading = false;
                if (res.code == '200') {
                    this.resourceTypeGroup = res.body;
                }
            }).catch(error => {
                this.loading = false;
            })
        },
        getResourceSubjectGroup() {
            this.loading = true;
            axios.post(this.$api.resourceSubjectGroup).then(res => {
                this.loading = false;
                if (res.code == '200') {
                    this.resourceSubjectGroup = res.body;
                }
            }).catch(error => {
                this.loading = false;
            })
        },
        getResourceMajorGroup() {
            this.loading = true;
            axios.post(this.$api.resourceMajorGroup).then(res => {
                this.loading = false;
                if (res.code == '200') {
                    this.resourceMajorGroup = res.body;
                }
            }).catch(error => {
                this.loading = false;
            })
        },
        getResourceCourseGroup() {
            this.loading = true;
            axios.post(this.$api.resourceCourseGroup).then(res => {
                this.loading = false;
                if (res.code == '200') {
                    this.resourceCourseGroup = res.body;
                }
            }).catch(error => {
                this.loading = false;
            })
        },
        getResourceFormatGroup() {
            this.loading = true;
            axios.post(this.$api.resourceFormatGroup).then(res => {
                this.loading = false;
                if (res.code == '200') {
                    this.resourceFormatGroup = res.body;
                }
            }).catch(error => {
                this.loading = false;
            })
        },
    }
  };
</script>

<style>

</style>
